/*
 * Application.fx
 *
 * Created on 14-apr-2009, 0:36:57
 */

package fotoboek.assets;
import javafx.scene.Group;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.Node;
import javafx.scene.text.Text;

/**
 * @author r.mohammadi
 */

public class Application {
public-init var application:Group on replace{
    background = application.content[0] as Group;
    logo = background.content[1] as Node;
    titleBar = application.content[3] as Group;
    titleSkin = titleBar.content[0] as Node;
    titleLabel = titleBar.content[1] as Text;
    screen = application.content[1] as Node;

}
public-init var logo:Node;

public-init var titleBar:Group;
public-init var titleSkin:Node;
public-init var titleLabel: Text;

public-init var background:Group;
public-init var screen:Node;

public-init var leftButton:Group;
public-init var rightButton:Group;
//public var imgHeight:Number;
//public var imgWidth:Number;
//public var imgUrl:String;
public var headerLabel: String on replace {
        if (headerLabel != null) {
            titleLabel.content = headerLabel;
          //  align(titleSkin, titleLabel);
        }
    }

public var buttonBar:HBox = HBox{
    spacing:15
    content:[
        leftButton,
        rightButton
    ]
}
public var keyPressedAction: function(e:KeyEvent);
public var mousePressedAction:function(e:MouseEvent);
public var mouseDraggedAction:function(e:MouseEvent);
public var mouseReleasedAction:function(e:MouseEvent);
public var content:Group;

public var MainScreen:VBox = VBox{
    content: [
        titleBar,
            Group{
                content:[
                    background,
                    content,
                    buttonBar
                ]
            }
        ]
    };

init{
   buttonBar.translateY = 265;
  // img.toBack();
   MainScreen.onKeyPressed = keyPressedAction;
   MainScreen.onMousePressed = mousePressedAction;
   MainScreen.onMouseDragged = mouseDraggedAction;
   MainScreen.onMouseReleased = mouseReleasedAction;

}

    function align( target:Node, dest:Node ) {
        var destBounds = dest.layoutBounds;
        var targetBounds = target.layoutBounds;
        // center X
        var leftX = (targetBounds.minX - destBounds.minX) - dest.translateX;
        dest.translateX = leftX + (targetBounds.width - destBounds.width)/2;

        // center Y
        var topY = (targetBounds.minY - destBounds.minY) - dest.translateY;
        dest.translateY = topY + (targetBounds.height - destBounds.height)/2;
    }
}




